package com.tim.app.server.api;

import com.application.library.net.ResponseCallback;
import com.lzy.okhttputils.cache.CacheMode;
import com.tim.app.RT;
import com.tim.app.server.logic.UserManager;
import com.tim.app.server.net.HttpMethod;
import com.tim.app.server.net.NetworkInterface;

import java.util.HashMap;

/**
 *
 */
public class API_Discover {

    private static volatile API_Discover api = null;

    private static String API_DISCOVER_SCHEME = "";

    private static final String GET_SPECIAL_LIST = "/moli_discover_consumer/specialtopic/v1/selectSpecialTopic";//专题列表

    private static final String GET_EVERYDAY_HEAD_LIST = "/moli_discover_consumer/everymusic/v1.2.0/selectAllEveryMusic";//每日一听的数据

    private static final String GET_MUSIC_ALBUM_LIST = "/moli_discover_consumer/album/v1.2.0/selectAllAlbum";//获取音乐专辑的数据

    private static final String GET_SPECIAL_DATA_LIST = "/moli_discover_consumer/specialtopicinfo/v1/selectSpecialTopicInfo";//获取专题内容数据

    private static final String GET_MUSIC_ALBUM_DETAIl = "/moli_discover_consumer/album/v1.2.0/selectAlbum";//获取专辑详情

    private static final String GET_MUSIC_ALBUM_DATA_LIST = "/moli_discover_consumer/album/v1.2.0/selectMusicAlbum";//获取专辑音频的数据

    private static final String GET_FOUND_CACHE_UPDATE_INFO = "/moli_discover_consumer/v1/configure/selectConfigureInfo";//获取缓存的更新信息

    private API_Discover() {

    }

    public static API_Discover ins() {
        if (api == null) {
            synchronized (API_Discover.class) {
                if (api == null) {
                    api = new API_Discover();
                    switch (RT.HOST) {
                        case DEVELOP:
//                            API_DISCOVER_SCHEME = "http://192.168.1.26:8082";
                            API_DISCOVER_SCHEME = "http://192.168.1.28:8086";
                            break;
                        case DEBUG:
                            API_DISCOVER_SCHEME = "";
                            break;
                        case PUBLISH:
                            API_DISCOVER_SCHEME = "";
                            break;
                    }
                }
            }
        }
        return api;
    }

    /**
     * 获取专题信息
     *
     * @param tag
     * @param pageNum
     * @param callback
     */
    public void getSpeciaList(String tag, int pageNum, int pageSize, CacheMode mode, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_SPECIAL_LIST;
        HashMap<String, Object> params = new HashMap<>();
        if (UserManager.ins().isLogin()) {
            params.put("uid", UserManager.ins().getUserId());
        }
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, mode, false, callback);
    }

    /**
     * 获取首页每日一听的数据
     *
     * @param tag
     * @param mode
     * @param callback
     */
    public void getHotEveryDayHearData(String tag, CacheMode mode, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_EVERYDAY_HEAD_LIST;
        HashMap<String, Object> params = new HashMap<>();
        params.put("everyMusicSort", 1);//1:权重倒序排2:创建时间倒序排3:创建时间顺序排
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, mode, false, callback);
    }

    /**
     * 获取每日一听的数据
     *
     * @param tag
     */
    public void getEveryDayHearList(String tag, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_EVERYDAY_HEAD_LIST;
        HashMap<String, Object> params = new HashMap<>();
        params.put("everyMusicSort", 1);//1:权重倒序排2:创建时间倒序排3:创建时间顺序排
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, CacheMode.DEFAULT, false, callback);
    }

    /**
     * 获取音乐专辑的数据
     *
     * @param tag
     * @param pageNum
     * @param pageSize
     * @param mode
     * @param callback
     */
    public void getMusicAlbumList(String tag, int pageNum, int pageSize, CacheMode mode, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_MUSIC_ALBUM_LIST;
        HashMap<String, Object> params = new HashMap<>();
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, mode, false, callback);
    }

    /**
     * 获取专题数据详情
     *
     * @param tag
     * @param specialId
     * @param pageNum
     * @param pageSize
     * @param callback
     */
    public void getSpecialDataList(String tag, String specialId, int pageNum, int pageSize, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_SPECIAL_DATA_LIST;
        HashMap<String, Object> params = new HashMap<>();
        params.put("specialId", specialId);
        if (UserManager.ins().isLogin()) {
            params.put("uid", UserManager.ins().getUserId());
        }
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, CacheMode.DEFAULT, false, callback);
    }


    /**
     * 获取专辑详情
     *
     * @param tag
     * @param id       专辑的id
     * @param callback
     */
    public void getMusicAlbumDetailData(String tag, String id, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_MUSIC_ALBUM_DETAIl;
        HashMap<String, Object> params = new HashMap<>();
        params.put("id", id);
        if (UserManager.ins().isLogin()) {
            params.put("userId", UserManager.ins().getUserId());
        }
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, CacheMode.DEFAULT, false, callback);
    }

    /**
     *
     * @param tag
     * @param id 专辑id
     * @param albumSort 1:权重倒序排，2:创建时间倒序排,3:创建时间顺序排
     * @param pageNum
     * @param pageSize
     * @param callback
     */
    public void getMusicAlbumDataList(String tag, String id, int albumSort, int pageNum, int pageSize, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_MUSIC_ALBUM_DATA_LIST;
        HashMap<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("albumSort", albumSort);
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, CacheMode.DEFAULT, false, callback);
    }

    /**
     * 获取发现页面的缓存更新信息
     * @param tag
     * @param callback
     */
    public void getFoundCacheUpdateInfo(String tag, ResponseCallback callback) {
        String url = API_DISCOVER_SCHEME + GET_FOUND_CACHE_UPDATE_INFO;
        HashMap<String, Object> params = new HashMap<>();
        NetworkInterface.ins().connected(HttpMethod.GET, url, tag, params, CacheMode.DEFAULT, false, callback);
    }

}
